package com.example.studentsystem;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.studentsystem.bean.UserBean;
import com.example.studentsystem.dao.MyDao;

public class UPDATE2 extends AppCompatActivity implements View.OnClickListener {
    EditText id;
    EditText name;
    EditText sex;
    EditText banji;
    Button btn1,btn2;
    int num2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_u_p_d_a_t_e);
        id = findViewById(R.id.id);
        name=findViewById(R.id.name);
        sex=findViewById(R.id.sex);
        banji=findViewById(R.id.banji);
        btn1=findViewById(R.id.btn1);
        btn2=findViewById(R.id.btn2);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        Intent data = getIntent();
        UserBean userBean = (UserBean) data.getSerializableExtra("userbean");
        id.setText(userBean.getId()+"");
        name.setText(userBean.getName());
        sex.setText(userBean.getSex());
        banji.setText(userBean.getBanji());
        num2 = data.getIntExtra("k",-1);
        System.out.println(num2);
    }

    @Override
    public void onClick(View view) {
        int num = view.getId();
        Intent intent = new Intent();
        switch (num){
            case R.id.btn1:
                MyDao myDao = new MyDao(this);
                UserBean userBean = new UserBean();
                userBean.setNum(num2);
                userBean.setId(Integer.parseInt(id.getText().toString()));
                userBean.setName(name.getText().toString());
                userBean.setSex(sex.getText().toString());
                userBean.setBanji(banji.getText().toString());
                intent.putExtra("b",userBean);
                myDao.update(userBean);
            case R.id.btn2:
                intent.setClass(this,DengLu2.class);
                startActivity(intent);
        }
    }
}